<template>
  <el-dialog title="添加法律法规" :visible.sync="dialogVisible" @opened="dialogOpen">
    <el-form ref="form" :model="form" label-width="80px" size="small">
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item prop="strName" label="法规标题">
            <el-input v-model="form.strName"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item prop="bCode" label="法规编码">
            <el-input v-model="form.bCode"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item prop="strNumber" label="发布文号">
            <el-input v-model="form.strNumber"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item prop="strOrgan" label="发布机关">
            <el-input v-model="form.strOrgan"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item prop="fgxlType" label="法规效力">
            <el-input v-model="form.fgxlType"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item prop="webLink" label="网站链接">
            <el-input v-model="form.webLink"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item prop="industryType" label="行业类型">
            <el-select v-model="form.industryType" placeholder="请选择">
              <el-option
                v-for="item in publics"
                :key="item.id"
                :label="item.name"
                :value="item.code"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item prop="dtmDate" label="发布时间">
            <el-input v-model="form.dtmDate"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item prop="shiDate" label="实施时间">
            <el-input v-model="form.shiDate"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item prop="status" label="时效性">
            <el-input v-model="form.status"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item prop="strnote" label="题注">
            <el-input v-model="form.strnote"></el-input>
          </el-form-item>
        </el-col>
       </el-row>
      <el-form-item>
        <el-button type="primary" :loading="loading" @click="saveUser">保存</el-button>
        <el-button @click="close">取消</el-button>
      </el-form-item>
    </el-form>
  </el-dialog>
</template>
<script>
import bnslawApi from "@/api/system/bnslaw";
import publicApi from "@/api/system/sysPublic";
export default {
  name: "bnslawAddForm",
  props: {
    value: Boolean
  },
  data() {
    return {
      loading: false,
      dialogVisible: false,
      form: {
        bcode: "",
        dtmDate: "",
        shiDate: "",
        status: "",
        strAnnex: "",
        strName: "",
        strnote: "",
        strNumber: "",
        strOrgan: "",
        webLink: "",
        fgxlType: "",
        industryType: ""
      },
      publics: []
    };
  },
  watch: {
    value(val) {
      this.dialogVisible = val;
    },
    dialogVisible(val) {
      this.$emit("input", val);
    }
  },
  methods: {
    dialogOpen() {
      this.$refs.form.resetFields();
      this.getPublicByType("0055");
    },
    getPublicByType(type) {
      publicApi.getPublicByType({ type: type }).then(res => {
        var data = res.data;
        this.publics = data;
      });
    },

    saveUser() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.loading = true;
          bnslawApi.add({ ...this.form }).then(data => {
            this.loading = false;
            this.dialogVisible = false;
            this.$emit("submit");
          });
        } else {
          return false;
        }
      });
    },
    close() {
      this.$refs["form"].resetFields();
      this.dialogVisible = false;
    }
  }
};
</script>

